<template>
	<view>
		<view class="example">
			<uni-forms ref="valiForm" :modelValue="valiFormData">
				<uni-forms-item label="用车部门" name="userDepartment">
					<uni-easyinput v-model="valiFormData.userDepartment" placeholder="请输入用车部门"
						disabled=""></uni-easyinput>
				</uni-forms-item>
				<uni-forms-item label="姓名" name="userName">
					<uni-easyinput v-model="valiFormData.userName" placeholder="请输入姓名" disabled />
				</uni-forms-item>
				<uni-forms-item label="工号" name="userId">
					<uni-easyinput v-model="valiFormData.userId" placeholder="请输入工号" disabled />
				</uni-forms-item>
				<uni-forms-item label="申请人电话" name="userPhone">
					<uni-easyinput v-model="valiFormData.userPhone" placeholder="请输入电话" disabled />
				</uni-forms-item>
				<uni-forms-item label="车型" name="autoType">
					<uni-easyinput v-model="valiFormData.autoType" placeholder="请输入车型" disabled=""></uni-easyinput>
				</uni-forms-item>
				<uni-forms-item label="成员数" name="passengerNum">
					<uni-easyinput v-model="valiFormData.passengerNum" placeholder="请输入成员数" disabled />
				</uni-forms-item>
				<uni-forms-item label="取车时间" name="autoStartTime">
					<uni-datetime-picker type="datetime" return-type="string" v-model="valiFormData.autoStartTime"
						disabled />
				</uni-forms-item>
				<uni-forms-item label="截止时间" name="autoArriveTime">
					<uni-datetime-picker type="datetime" return-type="string" v-model="valiFormData.autoArriveTime"
						disabled />
				</uni-forms-item>
				<uni-forms-item label="用车事宜" name="autoUseReason">
					<uni-easyinput type="textarea" v-model="valiFormData.autoUseReason" placeholder="请输入用车事宜"
						disabled />
				</uni-forms-item>
			</uni-forms>
		</view>
	</view>
	<view class="divider"></view>
	<view class="buttenBorder">
		<uni-forms :modelValue="baseFormData">
			<uni-forms-item label="审批人" name="orderApprover">
				<uni-easyinput v-model="baseFormData.orderApprover" placeholder="请输入审批人" disabled />
			</uni-forms-item>
			<uni-forms-item label="审批意见" name="approvalResult">
				<uni-easyinput v-model="baseFormData.approvalResult" placeholder="请输入审批意见" disabled />
			</uni-forms-item>
			<uni-forms-item label="车辆分配" name="autoPlateNum">
				<uni-easyinput v-model="baseFormData.autoPlateNum" placeholder="请输入车辆分配" disabled />
			</uni-forms-item>
			<uni-forms-item label="驾驶员分配" name="driverId">
				<uni-easyinput v-model="baseFormData.driverId" placeholder="请输入驾驶员分配" disabled />
			</uni-forms-item>
			<uni-forms-item label="审批备注">
				<uni-easyinput type="textarea" v-model="baseFormData.approvalDescribe" placeholder="请输入审批备注" disabled />
			</uni-forms-item>
		</uni-forms>
	</view>

</template>

<script>
	import AutoApplyInfo from "/components/autoApplyInfo/autoApplyInfo.vue"
	import SecondApproval from "/components/secondApproval/secondApproval.vue"
	export default {
		data() {
			return {
				valiFormData: {
					userDepartment: "",
					userName: "",
					userId: "",
					userPhone: "",
					autoType: "",
					passengerNum: "",
					autoStartTime: "",
					autoArriveTime: "",
					autoUseReason: "",
				},
				baseFormData: {
					orderApprover: "",
					approvalResult: "",
					autoPlateNum: "",
					driverId: "",
					approvalDescribe: "",
				},
				orderId: "",
			}
		},
		comments: {
			AutoApplyInfo,
			SecondApproval
		},
		methods: {
			getAutoOrderById(orderId) {
				uni.request({
					url: "http://localhost:8088/getAutoOrderById?orderId=" + this.orderId,
					method: "GET",
					success: (res) => {
						if (res.data.code === '0') {
							console.log(res.data.data);
							// 数据请求成功，将数据绑定到 valiFormData
							this.valiFormData = res.data.data; // 这里假设后端返回的数据结构中有一个 data 字段存储实际数据
						} else {
							console.error("1数据请求失败");
						}
					},
					fail: (err) => {
						console.error("数据请求失败", err);
					},
				})
			},
			getAppovalInfoById() {
				uni.request({
					url: "http://localhost:8088/getAutoGeneralApproval?orderId=" + this.orderId,
					method: "GET",
					success: (res) => {
						if (res.data.code === '0') {
							console.log(res.data.data);
							this.baseFormData = res.data.data;
						} else {
							console.log("2数据请求失败");
						}
					},
					fail: (err) => {
						console.log("数据请求失败", err);
					}
				})
			},
			getDriverNameBydriverId() {
				uni.request({
					url: "http://localhost:8088/getDriverNameById?driverId=" + this.baseFormData.driverId,
					method: "GET",
					success: (res) => {
						if (res.data.code === "0") {
							this.baseFormData = res.data.data;
						} else {
							console.log("3数据请求失败");
						}
					},
					fail: (err) => {
						console.log("数据请求失败", err);
					}
				})
			}
		},
		created() {
			const orderId = this.$route.query.orderId || ""; // 如果没有 orderId 参数，默认设置为空字符串
			this.orderId = orderId;
			console.log(this.orderId);
			this.getAppovalInfoById();
			this.getAutoOrderById();
		}
	}
</script>

<style lang="scss">
	.example {
		padding: 15px;
		background-color: #fff;
	}

	.segmented-control {
		margin-bottom: 15px;
	}

	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.form-item {
		display: flex;
		align-items: center;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		margin-left: 10px;
	}

	.divider {
		margin: 20rpx;
		background: #000;
		width: 95%;
		height: 1rpx;
	}

	.buttenBorder {
		padding: 15px;
		background-color: #fff;
	}
</style>